package com.itic.mall.system.service;

import com.itic.appbase.applications.redis.IRedisDao;
import com.itic.appbase.framework.utils.CalendarHelper;
import com.itic.mall.system.inter.users.usersmall.persistence.model.UsersMall;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


@Service
@Transactional
public class LoginRedisService implements com.itic.mall.system.inter.service.LoginRedisService{
    @Autowired
    private IRedisDao<String,UsersMall> iRedisDao;

    public void reflush(String key, UsersMall user ){
    	Date dateAfter7 = CalendarHelper.getDateAfter(new Date(), 7);
    	Long expiredTime = getSecondTimestamp(dateAfter7);
    	iRedisDao.set(key,user,expiredTime);
    }
    
    public UsersMall get(String key){
    	return (UsersMall)iRedisDao.get(key);
    }
    
    /** 
     * 获取精确到秒的时间戳 
     * @return 
     */  
    public static long getSecondTimestamp(Date date){  
        if (null == date) {  
            return 0;  
        }  
        String timestamp = String.valueOf(date.getTime());  
        int length = timestamp.length();  
        if (length > 3) {  
            return Long.valueOf(timestamp.substring(0,length-3));  
        } else {  
            return 0;  
        }  
    }  

}